using Indiefreaks.Xna.Core;
using Indiefreaks.Xna.Physics.Entities;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using SynapseGaming.LightingSystem.Collision;
using SynapseGaming.LightingSystem.Rendering;

namespace Indiefreaks.AceOnSteroids.Entities
{
    /// <summary>
    /// The PlayerSpaceShip is a game entity inheriting from SceneObject used to render and control the Player spaceship
    /// It implements IContentHost in order to ease loading the SpaceShip model and material
    /// </summary>
    /// <remarks>Our current SpaceShip model is untextured and this will also show you how to manually create a custom model SunBurn material</remarks>
    public class PlayerSpaceShip : SceneObject, IContentHost
    {
        public PlayerSpaceShip()
        {
            // we don't want the spaceship to respond to collision rather trigger some code to handle death.
            CollisionType = CollisionType.Trigger;
            // we'll implement later the code to manage the spaceship death in case it collides with asteroids.
        }

        #region Implementation of IContentHost

        public void LoadContent(IContentCatalogue catalogue, ContentManager manager)
        {
            // we load the spaceship model using standard ContentManager
            var model = manager.Load<Model>("Models/PlayerSpaceShip");

            // we then add it to the current SceneObject instance
            foreach (ModelMesh mesh in model.Meshes)
            {
                // we don't override the effect as we want to use the builtin SunBurn Processors.
                AddModelMesh(mesh, null);
            }

            // we now add the physics properties to our player spaceship using IGF's BEPUPhysics CollisionMove implementation.
            // we want a good level of collision precision so we'll use a ConvexHull.
            CollisionMove = new ConvexHullCollisionMove(this, model);
        }

        public void UnloadContent(IContentCatalogue catalogue)
        {
        }

        #endregion
    }
}